package com.zhongke.common.utils

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.zhongke.common.base.activity.HomeSecondActivity
import com.zhongke.common.base.fragment.ZKErrorFragment

/**
 * @author: ZhangQingHua
 * @date: 2021/11/22
 * @description
 */
object FragmentUtils {

    fun getFragment(fragmentName: String, data: Bundle? = null): Fragment {
        return try {
            val fragmentClass = Class.forName(fragmentName)
            val fragment = fragmentClass.newInstance() as Fragment
            if (data != null) {
                fragment.arguments = data
            }
            fragment
        } catch (ex: ClassNotFoundException) {
            ex.printStackTrace()
            ZKErrorFragment.newInstance(
                "ClassNotFound:\n$fragmentName"
            )
        }
    }

}